package com.elephantgreen.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * Singleton class to read properties/configurations settings
 * 
 * @author Shaminda Samaratunge
 *
 */
public class Config {

	private static Config config;
	
	/* Properties file name to be used. */
	private static final String PROP_FILE="/egconfig.properties";
	
	private Properties prop;
	
	public static synchronized Config getInstance() {
		if (config == null) {
			config = new Config();
		}
		
		return config;
	}
	
	private Config() {
		 try{  
	         InputStream is = Config.class.getResourceAsStream(PROP_FILE);  
	         prop = new Properties();  
	         prop.load(is);  
	         is.close();  
	       }catch(Exception e){  
	         System.out.println("Failed to read from " + PROP_FILE + " file.");  
	       }  		
	}
	
	public String readConfig(String key) {
        return prop.getProperty(key);  
	}

}
